<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h1>基础的get请求</h1>
    <form id="form" action="" method="">
        <input id="ipt" type="text">
        <button id="btn">输入学生id 查询他的详细信息</button>
    </form>
    <script>
        const Btn = document.getElementById('btn');
        const Ipt = document.getElementById('ipt');
        const Form = document.getElementById('form');
        Form.onsubmit = function () {
            const userId = Ipt.value

            const xhr = new XMLHttpRequest()

            /* 
                1.query传参,就是拼接在路径后的查询字符串
                2.get请求默认读取缓存,可以在query中额外添加一个的字符串为时间戳,让每次地址都不一致
            */
            xhr.open('get', `/user?${userID}&_=` + Date.now())

            xhr.send();

            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4 && (xhr.status >= 200 && xhr.status <= 299)) {

                    console.log(xhr.responseText);
                }
            }

            return false
        }
    </script>
</body>

</html>